<?php
/**
 * Created by PhpStorm.
 * User: insgeek
 * Date: 2017/2/22
 * Time: 12:04
 * 适配器模式2
 */
namespace DesignPattern\AdapterPattern;

interface BookInterface
{
    public function turnPage();

    public function open();

    public function getPage():int ;
}

class Book implements BookInterface
{
    private $page;

    public function open()
    {
        // TODO: Implement open() method.
        $this->page = 1;
    }

    public function turnPage()
    {
        // TODO: Implement turnPage() method.
        $this->page++;
    }

    public function getPage() : int
    {
        // TODO: Implement getPage() method.
        return $this->page;
    }

}

class EBookAdapter implements BookInterface
{
    protected $eBook;

    public function __construct(EBookInterface $EBook)
    {
        $this->eBook = $EBook;
    }

    public function open()
    {
        // TODO: Implement open() method.
        $this->eBook->unlock();
    }

    public function turnPage()
    {
        // TODO: Implement turnPage() method.
        $this->eBook->pressNext();
    }

    public function getPage() : int
    {
        // TODO: Implement getPage() method.
        return $this->eBook->getPage()[0];
    }
}

interface EBookInterface
{
    public function unlock();

    public function pressNext();

    public function getPage() :array ;
}

class Kindle implements EBookInterface
{
    private $page = 1;

    private $totalPages = 100;
    public function pressNext()
    {
        // TODO: Implement pressNext() method.
        $this->page++;
    }

    public function unlock()
    {
        // TODO: Implement unlock() method.
    }

    public function getPage(): array
    {
        // TODO: Implement getPage() method.
        return [$this->page, $this->totalPages];
    }
}

$kindle = new Kindle();
$book = new EBookAdapter($kindle);
$book->open();
$book->getPage();
$book->turnPage();
$book->getPage();
